import { JsonPipe } from '@angular/common';
import { ChangeDetectionStrategy, Component, Signal } from '@angular/core';
import { ErrorInfoService } from '../error-info.service';
import { SuccessInfoService } from '../success-info.service';
import { Info } from '../interface';

@Component({
  selector: 'app-demo2',
  standalone: true,
  imports: [JsonPipe],
  templateUrl: './demo2.component.html',
  styleUrl: './demo2.component.css',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class Demo2Component {
  successMessages: Signal<Info[]>;
  errorMessages: Signal<Info[]>;

  constructor(
    public successService: SuccessInfoService,
    public errorService: ErrorInfoService
  ) {
    this.successMessages = this.successService.all;
    this.errorMessages = this.errorService.all;
  }

  addSuccessInfo(message: string) {
    this.successService.record({ message, type: 'success' });
  }
  addErrorInfo(message: string) {
    this.errorService.record({ message, type: 'error' });
  }
}
